package com.yangrong.thread.chapter6;

/**
 * 开关方式结束生命周期
 * 
 * @author YangRong
 * @date 2020年5月26日
 */
public class ThreadCloseGraceful {

	private static class Worker extends Thread {
		private volatile boolean start = true;

		@Override
		public void run() {
			while (start) {
				// ...
			}
		}

		public void shutdown() {
			this.start = false;
		}
	}

	public static void main(String[] args) {
		Worker worker = new Worker();
		worker.start();

		try {
			Thread.sleep(10_000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		worker.shutdown();
	}

}
